/******************************************************************************
 * Filename : uc_hash.h
 * Created  : 2009-8-8 by franco.yin
 * Description -
 * 
 ******************************************************************************/

#ifndef _UC_HASH_H
#define _UC_HASH_H

#ifdef __cplusplus
extern "C" {
#endif

#include "uc_public.h"
#include "uc_list.h"

typedef struct _uchash_node {
	ucnode_s node_hash;
	ucnode_s node_list;
} uchash_node_s;

typedef struct uchash_table {
	uclist_s list;
	uclist_s *hash;
	int (*create_key) (uchash_node_s *pNode, void *p);
	void *p;
	int size;
	int cnt;
} uchash_table_s;

#define uchash_entry(pNode, type, node) uclist_entry(pNode, type, node)

extern uchash_table_s *uchash_create(int size, int (*create_key)(uchash_node_s *, void *), void *p);
extern void uchash_free(uchash_table_s *pTab);
extern int uchash_add(uchash_node_s *pNode, uchash_table_s * pTab);
extern int uchash_del(uchash_node_s *pNode, uchash_table_s *pTab);
extern int uchash_count(uchash_table_s *pTab);
extern int uchash_empty(uchash_table_s *pTab);
extern uchash_node_s *uchash_walk(uchash_table_s *pTab, int key, int (*func)(uchash_table_s *, uchash_node_s *, void *), void *p);
extern uchash_node_s *uchash_walk_all(uchash_table_s *pTab, int (*func)(uchash_table_s *, uchash_node_s *, void *), void *p);
extern uchash_node_s *uchash_walk_all_ext(uchash_table_s *pTab, int walk_cnt, int (*func)(uchash_table_s *, uchash_node_s *, void *, void *, void *), void *p1, void *p2, void *p3);
extern uchash_node_s *uchash_get_first(uchash_table_s *pTab);
extern uchash_node_s *uchash_get_last(uchash_table_s *pTab);

#ifdef __cplusplus
}
#endif

#endif				/* _UC_HASH_H */
